package com.tyl.thread01;

// 抢票
//发现问题，多个线程去操作同一个资源是数据婚紊乱
public class ThreadTest4 implements Runnable{

    //票数
    private  int tickename=10;
    @Override
    public void run() {
        while (true){
            if(tickename<=0){
                break;
            }
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"拿到了第"+tickename--+"张票");
        }
    }

    public static void main(String[] args) {
        ThreadTest4 ticke=new ThreadTest4();
        new Thread(ticke,"小明").start();
        new Thread(ticke,"黄牛").start();
        new Thread(ticke,"老师").start();
    }
}
